package com.stedu.mall.goodsservice.config;

import com.stedu.mall.common.interceptor.JwtInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration//配置类
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private JwtInterceptor jwtInterceptor;
    @Value("${stedu.picdir}")
    private String picdir;

    @Override
    //本地资源映射，通过浏览器访问服务器资源
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //处理路径可以是多个
        registry.addResourceHandler("/category/pic/**", "/goods/pic/**")
                .addResourceLocations("file:" + picdir);
    }

    //配置拦截器
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor)
                .addPathPatterns("/goods/**", "/category/**")//拦截的地址
                .excludePathPatterns("/category/allParent",
                        "/category/pic/**",
                        "/category/search",
                        "/goods/pic/**",
                        "/goods/search1",
                        "/comment/all");//不拦截的地址
    }
}
